﻿CREATE TABLE [dbo].[Semnaturi] (
    [IdSemnatura] SMALLINT      IDENTITY (1, 1) NOT NULL,
    [Nume]        VARCHAR (100) NOT NULL,
    [Functia]     VARCHAR (50)  NOT NULL,
    [Rand]        SMALLINT      CONSTRAINT [DF_Semnaturi_Rand] DEFAULT ((0)) NOT NULL,
    [Coloana]     SMALLINT      CONSTRAINT [DF_Semnaturi_Coloana] DEFAULT ((0)) NOT NULL,
    [System]      BIT           CONSTRAINT [DF_Semnaturi_System] DEFAULT ((0)) NOT NULL,
    [LaComanda]   BIT           CONSTRAINT [DF_Semnaturi_LaComanda] DEFAULT ((1)) NOT NULL,
    [LaReceptie]  BIT           CONSTRAINT [DF_Semnaturi_LaReceptie] DEFAULT ((1)) NOT NULL,
    CONSTRAINT [PK_Semnaturi] PRIMARY KEY CLUSTERED ([IdSemnatura] ASC)
);


GO

CREATE TRIGGER [dbo].[Block_Delete] 
   ON  [dbo].[Semnaturi]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @deSters smallint
	SET @deSters = 0
	SELECT @deSters = Count(*) from [Deleted] WHERE [System] = 1
	IF @deSters<>0
		GOTO Error1

    GOTO Gata
	Error1:
		RAISERROR ('Aplicatia nu poate fi stearsa deoarece apartine sistemului!', 16, 1)
		ROLLBACK TRANSACTION
	Gata:

END